import requests
import app


class YuanGong:
    def __init__(self):
        self.url = app.YUANGONG_url +"/api/sys/user"


    def deng(self,repdata):
        a =  requests.post(url=app.YUANGONG_url + "/api/sys/login", headers=app.HEARDERS, json=repdata)
        app.TOKEN = "Bearer " + a.json().get('data')
        app.HEARDERS["Authorization"] = app.TOKEN
        return a

    def jia(self,repdata):
        resp = requests.post(url=app.YUANGONG_url + '/api/sys/user',
                             headers=app.HEARDERS,
                             json=repdata)
        return resp

    def cha(self,emp_id):
        return requests.get(url=app.YUANGONG_url + "/api/sys/user/" + emp_id,
                            headers=app.HEARDERS)
    def xiugai(self,emp_id,repdata):
        return requests.put(url=app.YUANGONG_url +"/api/sys/user/" + emp_id,
                            headers=app.HEARDERS,
                            json=repdata)
    def shanchu(self,emp_id):
        return requests.delete(url=app.YUANGONG_url +'/api/sys/user/' + emp_id,
                               headers=app.HEARDERS)
    def chaliebiao(self):
        return requests.get(url=app.YUANGONG_url + '/api/sys/user?page=1&size=10',
                            headers=app.HEARDERS)





